package goutils

import (
	"context"
	"gitee.com/ichub/goconfig/common/base/basedto"
	"gitee.com/ichub/goconfig/common/base/baseutils/fileutils"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/glog"
)

/*
 * @Description:
 * @FilePath: \goconfig\common\configdto\baseutils\golog\go_log.go
 */

const (
	RotateSize = "100M" //1024 * 1024 * 20

	logfile_stat   = "gosys_stat.log"
	logfile_cli    = "gosys_cli.log"
	logfile_server = "gosys.log"
	logfile_err    = "gosys_err.log"
)

// https://blog.csdn.net/weixin_51261234/article/details/124504638
type GoLog struct {
	basedto.BaseEntitySingle

	Name   string
	logdir string
	*glog.Logger
}

func NewGoLog() *GoLog {
	var log = &GoLog{
		Logger: glog.New(),
	}

	return log.init()
}
func (l *GoLog) init() *GoLog {
	l.Logger.SetConfigWithMap(g.Map{
		"path":                 fileutils.FindBeanGofileUtil().FindRootDir() + "/logs",
		"level":                "all",
		"file":                 logfile_server,
		"stdout":               true,
		"StStatus":             0,
		"RotateSize":           RotateSize,
		"RotateBackupLimit":    10,
		"RotateBackupExpire":   "7d",
		"RotateBackupCompress": 9,
	})
	l.Logger.SetWriterColorEnable(true)

	return l

}

func (l *GoLog) SetLevelErr() *GoLog {

	l.Logger.SetLevel(glog.LEVEL_ERRO)
	return l

}

func (l *GoLog) SetLevel(level int) *GoLog {

	l.Logger.SetLevel(level)
	return l

}

func Info(v ...interface{}) {
	FindBeanGoLog().Info(context.Background(), v...)

}
func Debug(v ...interface{}) {
	FindBeanGoLog().Debug(context.Background(), v...)

}
